import 'package:flutter/material.dart';
import 'app_colors.dart';
import 'app_text_styles.dart';
import 'app_theme.dart';

/// 主题扩展
/// 提供一些辅助方法，帮助组件方便地使用主题
extension ThemeExtension on BuildContext {
  /// 获取主题数据
  ThemeData get theme => Theme.of(this);

  /// 获取颜色方案
  ColorScheme get colorScheme => theme.colorScheme;

  /// 获取文本主题
  TextTheme get textTheme => theme.textTheme;

  /// 获取是否是深色模式
  bool get isDarkMode => AppTheme.isDarkMode;

  /// 根据当前主题获取颜色
  Color getColor(Color lightColor, Color darkColor) {
    return AppTheme.getColor(lightColor, darkColor);
  }

  /// 获取主题下的颜色
  Color get primaryColor => colorScheme.primary;
  Color get secondaryColor => colorScheme.secondary;
  Color get backgroundColor => colorScheme.background;
  Color get surfaceColor => colorScheme.surface;
  Color get errorColor => colorScheme.error;

  /// 获取文本颜色
  Color get textColor => isDarkMode ? AppColors.darkText : AppColors.lightText;
  Color get textSecondaryColor =>
      isDarkMode ? AppColors.darkTextSecondary : AppColors.lightTextSecondary;

  /// 获取边框颜色
  Color get borderColor =>
      isDarkMode ? AppColors.darkBorder : AppColors.lightBorder;

  /// 获取分割线颜色
  Color get dividerColor =>
      isDarkMode ? AppColors.darkDivider : AppColors.lightDivider;

  /// 获取主题下的文本样式
  TextStyle get headline1 =>
      isDarkMode ? AppTextStyles.darkHeadline1 : AppTextStyles.lightHeadline1;
  TextStyle get headline2 =>
      isDarkMode ? AppTextStyles.darkHeadline2 : AppTextStyles.lightHeadline2;
  TextStyle get headline3 =>
      isDarkMode ? AppTextStyles.darkHeadline3 : AppTextStyles.lightHeadline3;
  TextStyle get subtitle1 =>
      isDarkMode ? AppTextStyles.darkSubtitle1 : AppTextStyles.lightSubtitle1;
  TextStyle get subtitle2 =>
      isDarkMode ? AppTextStyles.darkSubtitle2 : AppTextStyles.lightSubtitle2;
  TextStyle get bodyText1 =>
      isDarkMode ? AppTextStyles.darkBodyText1 : AppTextStyles.lightBodyText1;
  TextStyle get bodyText2 =>
      isDarkMode ? AppTextStyles.darkBodyText2 : AppTextStyles.lightBodyText2;
  TextStyle get caption =>
      isDarkMode ? AppTextStyles.darkCaption : AppTextStyles.lightCaption;
  TextStyle get button =>
      isDarkMode ? AppTextStyles.darkButton : AppTextStyles.lightButton;
}
